﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Job.Web.Framework
{
    public class MyRequest
    {
        // 提供统一处理的Request操作，以便控制所有页面参数输入
        public MyRequestValue this[string param]
        {
            get
            {
                return new MyRequestValue(HttpContext.Current.Request[param]);
            }
        }
    }

    public class MyRequestValue
    {
        private object _obj;
        public MyRequestValue(object obj)
        {
            _obj = obj;
        }


        /// <summary>
        /// 如果参数非整数，则返回-1
        /// </summary>
        public int IntValue
        {
            get
            {
                if (_obj != null)
                {
                    try
                    {
                        return Convert.ToInt32(_obj);
                    }
                    catch
                    {
                        return -1;
                    }
                }
                else
                {
                    return -1;
                }
            }
        }


        /// <summary>
        /// 如果参数非整数，则返回-1
        /// </summary>
        public Int64 Int64Value
        {
            get
            {
                if (_obj != null)
                {
                    try
                    {
                        return Convert.ToInt64(_obj);
                    }
                    catch
                    {
                        return -1;
                    }
                }
                else
                {
                    return -1;
                }
            }
        }
        public bool BoolValue
        {
            get
            {
                if (_obj != null)
                {
                    return Convert.ToBoolean(_obj);
                }
                else
                {
                    return false;
                }
            }
        }

        public string StringValue
        {
            get
            {
                if (_obj != null)
                {
                    return Convert.ToString(_obj);
                }
                else
                {
                    return "";
                }
            }
        }

        public object Value
        {
            get
            {
                return _obj;
            }
        }
    }
}
